Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MkSpeechBubble

github Show source on GitHub

Node for showing a css-based speech bubble.

Examples

Example: Regular

Note

Jinja

{{ "some text" | MkSpeechBubble }}

Note

Python

MkSpeechBubble()
Rendered

some text

Markdown
<div class="speech bottom">

some text

</div>
Html
<div class="speech bottom">
<p>some text</p>
</div>

GitHub
<div class="speech bottom">

some text

</div>
Repr tree
MkSpeechBubble
╰── MkText('some text')

Example: No arrow

Note

Jinja

{{ "some text" | MkSpeechBubble(arrow=None) }}

Note

Python

MkSpeechBubble(arrow=None)
Rendered

some text

Markdown
<div class="speech">

some text

</div>
Html
<div class="speech">
<p>some text</p>
</div>

GitHub
<div class="speech">

some text

</div>
Repr tree
MkSpeechBubble
╰── MkText('some text')
DocStrings

class MkSpeechBubble(mkcontainer.MkContainer)
Base classes
NameChildrenInherits
MkContainer
mknodes.basenodes.mkcontainer
A node containing other MkNodes.
⋔ Inheritance diagram
graph TD
  1965962441["mkspeechbubble.MkSpeechBubble"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  2751680898["builtins.object"]
  835538629 --> 1965962441
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
NodeFile

/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkspeechbubble/metadata.toml

[metadata]
icon = "mdi:chat"
name = "MkSpeechBubble"

[[resources.css]]
filename = "speechbubble.css"

[examples.regular]
title = "Regular"
jinja = """
{{ "some text" | MkSpeechBubble }}
"""

[examples.no_arrow]
title = "No arrow"
jinja = """
{{ "some text" | MkSpeechBubble(arrow=None) }}
"""

[output.markdown]
template = """
<div class="speech{{ node.arrow | add(prefix=' ') }}" markdown="1">
{{node.get_items()  | join(node.block_separator) }}
</div>
"""

Code

mknodes.basenodes.mkspeechbubble.MkSpeechBubble

class MkSpeechBubble(mkcontainer.MkContainer):
    """Node for showing a css-based speech bubble."""

    ICON = "material/chat"
    CSS = [resources.CSSFile("speechbubble.css")]

    def __init__(
        self,
        content: str | mknode.MkNode | list | None = None,
        *,
        arrow: Literal["top", "bottom", "left", "right"] | None = "bottom",
        **kwargs: Any,
    ) -> None:
        self.arrow = arrow
        super().__init__(content=content or [], **kwargs)

    def get_element(self) -> xml.Div:
        klass = f"speech {self.arrow}" if self.arrow else "speech"
        root = xml.Div(klass, markdown=True)
        root.text = "\n" + super().to_md_unprocessed() + "\n"
        return root

    def to_md_unprocessed(self) -> str:
        element = self.get_element()
        return element.to_string()

Page info
Code for this page

mknodes.manual.nodes_section.create_section_for_nodes

def create_section_for_nodes(
    nav: mk.MkNav,
    klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
    for kls in klasses:
        tpl = "classpage_custom.jinja"
        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
        nav += page
        if kls.STATUS:
            page.metadata.status = kls.STATUS
        elif kls.JS_FILES:
            page.metadata.status = "js"
        elif kls.CSS:
            page.metadata.status = "css"
        page.created_by = create_section_for_nodes
        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
        table.add_row((link, kls.__doc__, extensions))
    return table

Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x7d707a397060>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: material/chat
status: css
title: MkSpeechBubble